package cn.ingrun.ingrunutils.responseUtil;

import java.util.List;

public class ResponseModel {

    private int code;
    private String message;
    private Object data;

    public ResponseModel () {
    }

    public ResponseModel (int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = this.removePassword(data);
    }

    // 过滤掉用户的中的密码信息
    @SuppressWarnings("all")
    private Object removePassword(Object data) {

        if ( data instanceof UserBase ){
            UserBase data1 = (UserBase) data;
            data1.setPassword("");
            return data1;
        }

        if (data instanceof List) {
            List<?> data1 = (List<?>) data;
            if (data1.size() > 0) {
                Object o = data1.get(0);
                if (o instanceof UserBase) {
                    List<UserBase> data11 = (List<UserBase>) data1;
                    for (UserBase user : data11) {
                        user.setPassword("");
                    }
                }
            }
        }
        return data;
    }


    @Override
    public String toString() {
        return "ResponseModel{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
